package com.lx.index.web.feign;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.lx.bean.Result;
import com.lx.dm.entity.Category;
import com.lx.dm.entity.Product;
import com.lx.dm.entity.User;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Component
// 一个服务只能有一个接口
@FeignClient(name = "cloud-others", fallback = OtherActionImpl.class)
public interface OtherAction {

    @RequestMapping("product/hots")
    List<Product> queryHots() throws JsonProcessingException;

    @RequestMapping("category/getCate")
    List<Category> getCate();

    @RequestMapping("product/news")
    List<Product> queryNews();

    @RequestMapping("product/getProductById")
    Product getProductById(Integer id);












    // 高版本JDK加@RequestParam()
    @RequestMapping("feign/add")
    int add(@RequestParam("a") int a,
            @RequestParam("b") int b);

    // 对象属性映射为请求参数名 自动装箱
    @RequestMapping("feign/res")
    Result res(@SpringQueryMap Result r);

    // 用户信息通过 请求体body 传递过来
    @RequestMapping("feign/user")
    User user(@RequestBody User user,
              @RequestParam("myname") String myname);


    // RESTful 请求方式的地址参数
    @RequestMapping("feign/hello/{nm}")
    String hello(@PathVariable("nm") String name);
}
